﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraEditors;
using TT.Module.sysLogin;
using System.IO;
using Dev.Control;
using Bill.BasForm;
using Exp.BillDLL.biz;
using TT.ORM;
using ExpBillMain.form;
using DevExpress.XtraSplashScreen;

namespace ExpBillMain
{
    public partial class frmMain : Dev.Control.MainForm
    {
        string sDefUserFileName = System.IO.Directory.GetCurrentDirectory() + @"\User_Def.xml";
        bizExpBill bzExpBill;

        public frmMain()
        {
            InitializeComponent();
            ShowFormThis();
            InitSkinGallery();
            SplashScreenManager.CloseForm();
        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
            SkinHelper.InitSkinGallery(rgbiSkins2, true);
            SkinHelper.InitSkinGallery(rgbiSkins3, true);
            SkinHelper.InitSkinGallery(rgbiSkins4, true);
            SkinHelper.InitSkinGallery(rgbiSkins5, true);
        }

        private void ribbon_SelectedPageChanged(object sender, EventArgs e)
        {
            ShowFormThis();
        }

        #region CurrentForm属性
        //XtraForm CurrentForm
        //{
        //    get
        //    {
        //        if (this.ActiveMdiChild == null) return null;
        //        return this.ActiveMdiChild as XtraForm;
        //    }
        //}

        //private void xtraTabbedMdiManager1_FloatMDIChildActivated(object sender, EventArgs e)
        //{
        //    ChangeActiveForm();
        //}
        //private void xtraTabbedMdiManager1_FloatMDIChildDeactivated(object sender, EventArgs e)
        //{
        //    BeginInvoke(new MethodInvoker(ChangeActiveForm));
        //}
        //void ChangeActiveForm()
        //{

        //}
        #endregion

        private void MainFormSms_Load(object sender, EventArgs e)
        {

        }



        private void bbiFind_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.F10();
        }

        private void ribbon_Click(object sender, EventArgs e)
        {
            if (htForms.Count == 0)
            {
                ShowFormThis();
            }
        }

        private void ShowFormThis()
        {
            RibbonPage rpCurrent = ribbon.SelectedPage;
            string sCurrFormName = rpCurrent.Name;
            if (ShowForm(sCurrFormName) == false)
            {
                object fmNewForm = null;
                switch (sCurrFormName)
                {
                    case "rbpBillPrice":
                        fmNewForm = new frmBillPrice(_Global.basSysPara, "",_Global.ilBussType,_Global.ilSF,_Global.ilCity,_Global.ilQX);
                        break;
                    case "rbpChrgFavour":
                        fmNewForm = new frmChrgFavour(_Global.basSysPara, _Global.ilBussType, _Global.ilSF, _Global.ilCity, _Global.ilQX);
                        break;
                    case "rbpArea":
                        fmNewForm = new frmArea(_Global.basSysPara, false, _Global.ilBussType, _Global.ilSF);
                        break;
                    case "rbpDetail":
                        fmNewForm = new frmExpDetail();
                        break;
                    case "rbpInvoiceHdr":
                        fmNewForm = new frmInvoiceHdr();
                        break;
                }
                if (fmNewForm != null)
                    NewForm(sCurrFormName, (BaseFormDev)fmNewForm);
            }
        }

        private void bbiAddArea_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.NewData();
        }

        private void bbiFind_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            ActivityForm.F11();
        }

        private void bbiUpdate_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.F11();
        }

        private void bbiDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.F9();
        }

        private void bbiDelFav_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.F9();
        }

        private void bbiAddFav_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.F10();
        }

        private void bbiUpdateFav_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.F11();
        }
        private void bbiSetPrice_ItemClick(object sender, ItemClickEventArgs e)
        {
            //if (string.IsNullOrWhiteSpace(frmChrgFavour.favPriceId))
            //{
            //    MessageBox.Show("请先选择达量范围！");
            //    return;
            //}
            //frmBillPrice fmPrice = new frmBillPrice(_Global.basSysPara, frmChrgFavour.favPriceId, _Global.ilBussType);
            ////NewForm("FavPrice", (BaseFormDev)fmPrice);
            //fmPrice.ShowDialog();
        }

        private void bbiRefresh_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.F9();
        }

        private void bbtRefreshInvHdr_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.F9();
        }

        private void bbiRefreshPrice_ItemClick(object sender, ItemClickEventArgs e)
        {
            ActivityForm.RefreshDate();
        }
    }
}